use std::error::Error;

pub type FrameResult<T> = Result<T,FrameError>;

#[derive(Debug)]
pub enum FrameError {
    Byte(crate::byte::ByteError),
    Block(crate::block::error::BlockError),
    UnknownMagic(u32),
}

impl std::fmt::Display for FrameError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Byte(e) => write!(f,"[frame]{e}"),
            Self::UnknownMagic(num) => write!(f,"[frame]unkown magic number {num}"),
            Self::Block(b) => write!(f,"[frame]{b}"),
        }
    }
}

impl Error for FrameError { }

impl From<crate::byte::ByteError> for FrameError {
    fn from(value: crate::byte::ByteError) -> Self {
        Self::Byte(value)
    }
}

impl From<crate::block::error::BlockError> for FrameError {
    fn from(value: crate::block::error::BlockError) -> Self {
        Self::Block(value)
    }
}